/*
 * Filename:    EvaluationRuleDao.java
 * Copyright:   2015 中国平安保险（集团）股份有限公司 版权所有
 * Company:     平安科技养老险及健康险系统开发部
 * Create at:   2015-1-29
 */
package com.paic.mhis.hcpms.evaluation.evaluationRule.dao;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.paic.mhis.hcpms.evaluation.evaluationRule.dto.EvaluationCategoryDTO;
import com.paic.mhis.hcpms.evaluation.evaluationRule.dto.EvaluationContentDTO;
import com.paic.mhis.hcpms.evaluation.evaluationRule.dto.EvaluationMarkRuleDTO;
import com.paic.mhis.hcpms.evaluation.evaluationRule.dto.EvaluationMarkValueDTO;
import com.paic.mhis.hcpms.evaluation.evaluationRule.dto.EvaluationStandardScoreContentDTO;
import com.paic.mhis.hcpms.evaluation.evaluationRule.dto.EvaluationTypeDTO;
import com.paic.pafa.biz.dao.BaseDAO;

@Component("evaluationRuleDao")
public class EvaluationRuleDao extends BaseDAO {

	/**
	 * 根据扣分细则的id 删除对应的扣分细则
	 * 
	 * @param markValueId
	 */
	public void deleteEvaluationMarkValueById(String markValueId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("markId", markValueId);
		this._delete("evaluation.deleteEvaluationMarkInfoById", map);

	}

	/**
	 * 保存扣分细则对应的扣分分值对象
	 * 
	 * @param bean
	 */
	public void saveEvaluationMarkRuleValue(EvaluationMarkValueDTO bean) {

		this._insert("evaluation.insertEvaluationMarkValueInfo", bean);
	}

	/**
	 * 根据扣分细则的id 删除对应的扣分细则扣分信息
	 * 
	 * @param markValueId
	 */
	public void deleteEvaluationMarkRuleValueByMarkInfoId(String markValueId) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("markRuleId", markValueId);
		this._delete("evaluation.deleteEvaluationMarkValueInfo", map);

	}

	/**
	 * 根据规则类别:01医院,02药店加载对应的考评规则信息
	 * 
	 * @param categoryType
	 * @return
	 */
	public List<EvaluationCategoryDTO> queryEvaluationCategory(String categoryType, String id) {

		Map<String, Object> map = new HashMap<String, Object>();
		map.put("categoryType", categoryType);
		map.put("id", id);
		List<EvaluationCategoryDTO> list = (List<EvaluationCategoryDTO>) this._queryForList(
				"evaluation.queryEvaluationRule", map);

		return list;

	}

	/**
	 * 根据考评规则ID 加载对应的考核内容
	 * 
	 * @param categoryId
	 * @return
	 */
	public List<EvaluationContentDTO> queryEvaluationContentDTO(String categoryId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("categoryId", categoryId);

		List<EvaluationContentDTO> list = (List<EvaluationContentDTO>) this._queryForList(
				"evaluation.queryEvaluationRuleContent", map);

		return list;

	}

	/**
	 * 根据考核内容id加载对应的细则
	 * 
	 * @param contentId
	 * @return
	 */
	public List<EvaluationMarkRuleDTO> queryEvaluationMarkRuleDTO(String contentId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("contentId", contentId);
		List<EvaluationMarkRuleDTO> list = (List<EvaluationMarkRuleDTO>) this._queryForList(
				"evaluation.queryEvaluationMarkRule", map);

		return list;
	}

	/**
	 * 根据考核细则id 加载对应的扣分值信息
	 * 
	 * @param markInfoId
	 * @return
	 */
	public List<EvaluationMarkValueDTO> queryEvaluationMarkValueDTO(String markInfoId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("markInfoId", markInfoId);
		List<EvaluationMarkValueDTO> list = (List<EvaluationMarkValueDTO>) this._queryForList(
				"evaluation.queryEvaluationMarkValues", map);

		return list;
	}

	/**
	 * 删除考评规则
	 * 
	 * @param categroyId
	 */
	public void deleteEvaluationRule(String categroyId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("categroyId", categroyId);
		this._delete("evaluation.deleteEvaluationRule", map);
	}

	/**
	 * 删除考评内容
	 * 
	 * @param categroyId
	 */
	public void deleteEvaluationContent(String categroyId, String standardScoreId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("categroyId", categroyId);
		map.put("standardScoreId", standardScoreId);
		this._delete("evaluation.deleteEvaluationInfo", map);
	}

	/**
	 * 删除扣分细则
	 * 
	 * @param categroyId
	 */
	public void deleteEvaluationMarkInfo(String categroyId, String standardScoreId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("categroyId", categroyId);
		map.put("standardScoreId", standardScoreId);
		this._delete("evaluation.deleteEvaluationMark", map);
	}

	/**
	 * 删除扣分值信息
	 * 
	 * @param categroyId
	 */
	public void deleteEvaluationMarkValue(String categroyId, String standardScoreId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("categroyId", categroyId);
		map.put("standardScoreId", standardScoreId);
		this._delete("evaluation.deleteEvaluationMarkValue", map);
	}

	/**
	 * 根据规则id加载对应的分值
	 * 
	 * @param categoryId
	 * @return
	 */
	public BigDecimal getEvaluationRuleAllScore(String categoryId) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("contentId", categoryId);
		BigDecimal value = new BigDecimal(0);
		Object score = (Object) this._queryForObject("evaluation.queryEvaluationRuleScore", map);
		if (score != null) {
			long currentScore = (Long) score;
			value = new BigDecimal(currentScore);
		}

		return value;

	}

	/**
	 * 查询考评类别
	 * 
	 * @return
	 */
	public List<EvaluationTypeDTO> queryAllRuleType(String scoreType) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("scoreType", scoreType);
		List<EvaluationTypeDTO> list = (List<EvaluationTypeDTO>) this._queryForList(
				"evaluation.queryEvaluationRuleType", map);

		return list;

	}

	/**
	 * 根据评分标准的考评类别id 去加载对应的考核内容和扣分析则
	 * 
	 * @param standardTypeId
	 * @param scoreLevel
	 *            2 考核内容,3扣分细则
	 * @param scoreType
	 *            0,医院,2药店
	 * @return
	 */
	public List<EvaluationStandardScoreContentDTO> queryStandardScore(String standardTypeId, String scoreLevel,
			String scoreType) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("id", standardTypeId);
		map.put("scoreLevel", scoreLevel);
		map.put("scoreType", scoreType);
		List<EvaluationStandardScoreContentDTO> list = (List<EvaluationStandardScoreContentDTO>) this._queryForList(
				"evaluation.queryEvaluationStandardScore", map);

		return list;

	}

	/**
	 * 保存对应的考评组信息
	 * 
	 * @param bean
	 */
	public void saveEvualtionRuleInfo(EvaluationCategoryDTO bean) {
		this._insert("evaluation.insertEvaluationRuleInfo", bean);

	}

	/**
	 * 保存考评内容信息
	 * 
	 * @param bean
	 */
	public void saveEvaluationContentInfo(EvaluationContentDTO bean) {
		this._insert("evaluation.insertEvaluationContentInfo", bean);

	}

	/**
	 * 保存考评细则信息
	 * 
	 * @param bean
	 */
	public void saveEvaluationMarkInfo(EvaluationMarkRuleDTO bean) {
		this._insert("evaluation.insertEvaluationMarkInfo", bean);
	}

	/**
	 * 更新考评规则类别信息
	 * 
	 * @param bean
	 */
	public void updateEvaluationRuleInfo(EvaluationCategoryDTO bean) {

		this._update("evaluation.updateEvaluationRuleInfo", bean);

	}

}
